import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.Timer;

@SuppressWarnings("serial")
public class DigitalClock extends JLabel {
	private String pattern;
	private Timer timer;
	private int delay;

	public DigitalClock(String pattern){
		this.pattern = pattern;
		this.delay = 1000;
		createTimer();
		timer.start();
	}
  
 
	public DigitalClock(String pattern, int delay){
		this.pattern = pattern;
		this.delay = delay;
		createTimer();
		timer.start();
	}

 
	public DigitalClock(){
		pattern = "kk:mm:ss\ndd.MM.YYYY";
		this.delay = 1000;
		createTimer();
		timer.start();
	}
 
	private void createTimer(){
		timer = new Timer(delay, new ActionListener() {
			
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setText(new SimpleDateFormat(pattern).format(new Date()));
		}
		});
	}
  
	public String getPattern() {
		return pattern;
	}
  
	public void setPattern(String pattern) {
		this.pattern = pattern;
	}
  
	public Timer getTimer() {
		return timer;
	}
  
	public int getDelay() {
		return delay;
	}
  
	public void setDelay(int delay) {
		this.delay = delay;
	}
}